<?php

namespace control;


class EncryptionMethod
{
    const salt="xbtsjsb";//盐

    /**
     * @param $password
     * 普通的md5加密
     */
    public static function ts_md5($password,$raw_output=false){
        return md5(strtolower(self::salt."_".$password),$raw_output);
    }
    /**
     * @param $password
     * sha1 加密
     */
    public static function ts_sha1($password,$raw_output=false){
         return sha1(strtolower(self::salt."_".$password),$raw_output);
    }
    /**
     * @param $string
     * @param $key
     * @return string
     * ase 可逆加密
     */
    public static function ts_encrypt($string,$key){
        $data = openssl_encrypt($string, 'AES-128-ECB', $key, OPENSSL_RAW_DATA);
        return base64_encode($data);
    }
    /**
     * @param $string
     * @param $key
     * @return string
     * ase 可逆解密
     */
    public static function ts_dncrypt($string,$key){
        return openssl_decrypt(base64_decode($string), 'AES-128-ECB', $key, OPENSSL_RAW_DATA);
    }
    /**
     * 按算法打乱字符串顺序
     * way=true 打乱 way=false 恢复原本
     */
    public static function string_disorder($string,$way=true){
        $string=base64_encode($string);
        $str1=["1","a","2","A","3","B","b","4","c"];
        $str2=[".","?","!",",","@","$","#","<",">"];
        if($way){
            return str_replace($str1,$str2,$string);
        }else{
            return str_replace($str2,$str1,$string);
        }
    }
}